//========================================================================================
//  
//  $File: $
//  
//  Owner: Toan Nguyen
//  
//  $Author: $
//  
//  $DateTime: $
//  
//  $Revision: $
//  
//  $Change: $
//  
//  Copyright 1997-2008 Adobe Systems Incorporated. All rights reserved.
//  
//  NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance 
//  with the terms of the Adobe license agreement accompanying it.  If you have received
//  this file from a source other than Adobe, then your use, modification, or 
//  distribution of it requires the prior written permission of Adobe.
//  
//========================================================================================

#include "VCPlugInHeaders.h"

#include "IControlView.h"
#include "IInLineEditController.h"
#include "IPanelControlData.h"
#include "ITextControlData.h"

#include "CTreeViewWidgetMgr.h"
#include "AMPNodeID.h"
#include "AMPID.h"
//#include "WLBCmpRezDefs.h"
#include "AMGlobal.h"
#include "AMPLogDataRecord.h"
#include <iostream>
using namespace std;

/**
 *  Tree view manager
 */
class AMPTVWidgetMgr : public CTreeViewWidgetMgr
{
public:
	AMPTVWidgetMgr(IPMUnknown *boss);
	virtual ~AMPTVWidgetMgr()
	{}
    
    virtual bool16	ApplyDataToWidget( const NodeID& node, IPanelControlData* widgetList, int32 message ) const;

    void RegisterStyles()
    {
        RegisterStyleWidget(kLargePaletteRowsTreeStyle, kAMPluginListElementRsrcID, kAMPPluginID);
    }
};


CREATE_PMINTERFACE(AMPTVWidgetMgr, kAMPTVWidgetMgrImpl)

AMPTVWidgetMgr::AMPTVWidgetMgr(IPMUnknown *boss) :
CTreeViewWidgetMgr(boss, kList)
{
	// added by Vu Tiet
	// create workspace dir
	//AMPUtils::CreateWorkspaceDir();		
	//InitLogHeaderFile();
	// add doc watch 
	//printf("AMPTVWidgetMgr::AMPTVWidgetMgr add doc watch \n");
	//AMPUtils::DoUseResponder();
	
}


/********************************************************************************************************************
 *****Function: ApplyDataToWidget
 *****Creator:  Toan Nguyen
 *****IN: 
 *****out: 
 *****Objective: 
 ********************************************************************************************************************/
bool16 AMPTVWidgetMgr::ApplyDataToWidget(const NodeID& node, 
                                            IPanelControlData* widgetList, 
                                            int32 message) const
{
	do
	{
		//cout << "AMPTVWidgetMgr::ApplyDataToWidget" << endl;
		TreeNodePtr<AMPNodeID> nodeID(node);
		PMString listName = nodeID->GetName();
		//cout << "listName " << listName.GrabCString() << endl;
	   
		IControlView* nameView = widgetList->FindWidget(kAMPluginTextWidgetID);
		InterfacePtr<ITextControlData>	textControlData( nameView, UseDefaultIID() );
		ASSERT(textControlData);
		if( textControlData== nil) {
			break;
		}
		textControlData->SetString(listName);
		
		// disable or enable node
		if (g_IsLoggedIn == FALSE) {
			//PMString browseIssueNodeName("Browse Issues");
			PMString browseIssueNodeName(kAMPItemBaseKey);
			browseIssueNodeName.AppendNumber(2); // browser issues
			browseIssueNodeName.Translate();
			if (listName.Compare(false, browseIssueNodeName) == 0) {
				nameView->Disable(kTrue);
			}
		}
		else if(g_TextSelected == FALSE) {
			PMString checkInStoryName(kAMPItemBaseKey);
			checkInStoryName.AppendNumber(5); // check in story
			checkInStoryName.Translate();
			if (listName.Compare(false, checkInStoryName) == 0) {
				nameView->Disable(kTrue);
			}
			
			PMString checkOutStoryName(kAMPItemBaseKey);
			checkOutStoryName.AppendNumber(6); // check out story
			checkOutStoryName.Translate();
			if (listName.Compare(false, checkOutStoryName) == 0) {
				nameView->Disable(kTrue);
			}
		}
		else {
			nameView->Enable(kTrue, kTrue);
		}
		
		
	} while (false);	
	return kTrue;
}

